/*
	PlAr is Platform Arena: a 2D multiplayer shooting game
	Copyright (c) 2010, Antonio Ragagnin <spocchio@gmail.com>
    All rights reserved.

    This file is licensed under the New BSD License.
*/



package res.players;

import java.util.HashMap;
import plar.core.Action;
import plar.core.KeyFlag;
import plar.core.Sprite;
import plar.core.ElementPlayer;
import plar.core.SpriteSet;
import res.players.Queen.SpriteManager;

import org.jbox2d.common.Vec2;

public class KittyCat extends ElementPlayer {

    public class SpriteManager extends Action {
        int firing = 0;

        int index = 0;
        int maxFiring = 50;
        HashMap<String, SpriteSet> spriteSet;

        public SpriteManager() {
            spriteSet = new HashMap<String, SpriteSet>();
            spriteSet.put("none",null);
            spriteSet.put("move_right", new SpriteSet());
            spriteSet.put("move_left", new SpriteSet());
            spriteSet.put("jump_right", new SpriteSet());
            spriteSet.put("jump_left",new SpriteSet());
            spriteSet.put("stop_right",new SpriteSet());
            spriteSet.put("stop_left",new SpriteSet());
            spriteSet.put("fire_left",new SpriteSet());
            spriteSet.put("fire_right",new SpriteSet());
            spriteSet.put("jumpfire_left",new SpriteSet());
            spriteSet.put("jumpfire_right", new SpriteSet());
            spriteSet.put("down_left",new SpriteSet());
            spriteSet.put("down_right", new SpriteSet());
            String p = "res/players/kittycat/";

            spriteSet.get("stop_right").add(
                new Sprite(p+"kittysr.png", 0.1f));
            spriteSet.get("stop_left").add(
                new Sprite(p+"kittysl.png", 0.1f));
            spriteSet.get("move_right").add(
                new Sprite(p+"kittyrr0.png", 0.1f));
            spriteSet.get("move_right").add(
                new Sprite(p+"kittyrr1.png", 0.1f));
            spriteSet.get("move_right").add(
                new Sprite(p+"kittyrr2.png", 0.1f));
            spriteSet.get("move_right").add(
                new Sprite(p+"kittyrr3.png", 0.1f));
            spriteSet.get("move_left").add(
                new Sprite(p+"kittyrl0.png", 0.1f));
            spriteSet.get("move_left").add(
                new Sprite(p+"kittyrl1.png", 0.1f));
            spriteSet.get("move_left").add(
                new Sprite(p+"kittyrl2.png", 0.1f));
            spriteSet.get("move_left").add(
                new Sprite(p+"kittyrl3.png", 0.1f));
            spriteSet.get("jump_left").add(
                new Sprite(p+"kittyrl1.png", 0.1f));
            spriteSet.get("jump_right").add(
                new Sprite(p+"kittyrr1.png", 0.1f));
            spriteSet.get("down_left").add(
                new Sprite(p+"kittydl.png", 0.1f));
            spriteSet.get("down_right").add(
                new Sprite(p+"kittydr.png", 0.1f));
            spriteSet.get("fire_left").add(
                new Sprite(p+"kittyrlf.png", 0.1f));
            spriteSet.get("fire_right").add(

                new Sprite(p+"kittyrrf.png", 0.1f));
        }

        public  void run() {

            boolean isRunning = (getSpeed().x != 0);


            if (firing > maxFiring)  firing = 0;
            String spriteSuffix;
            if(directionX >0) spriteSuffix="_right";
            else spriteSuffix="_left";
            String spriteName=new String();

            if(invisible) spriteName = "none";     //invisibility ovverides all
            else if (firing > 0 || isFiring) {
                spriteName = "fire";
                firing++;
            }
            else if (isJumping ) spriteName = "jump";
            else  if (isRunning && !isJumping ) spriteName = "move";
			else  if (isBending ) spriteName = "down";
            else  if (!isRunning && !isJumping ) spriteName = "stop";




            if(!invisible) spriteName+=spriteSuffix;
            currentSpriteSet = spriteSet.get(spriteName);


        }
    }
    public boolean invisible;
    public float specialDamage;
    public KittyCat() {
        super();

        name = "KittyCat";
        reducedSize =  new Vec2(0.6f,0.35f);
        standardSize =  new Vec2(0.3f,0.7f);
        description = "use the SPECIAL key to become INVISIBLE";
        presentation = "res/players/kittycat/kittysr.png";

        actions.addAction("actionManager", new SpriteManager());



    }
    public void initComponents() {
        invisible=false;
        specialDamage=1;

    }
    public void allKeysReleased() {
        invisible = false ;

    }

    public void specialMove(KeyFlag k) {

        invisible = true ;
        energy-=0.1;

    }

}
